package com.jiuli_travel.travel_service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.jiuli_travel.attraction_service.model.entity.Attraction;
import com.jiuli_travel.attraction_service.service.IAttractionService;
import com.jiuli_travel.travel_service.model.entity.ItineraryStops;
import com.jiuli_travel.travel_service.mapper.ItineraryStopsMapper;
import com.jiuli_travel.travel_service.model.vo.ItineraryStopsVO;
import com.jiuli_travel.travel_service.service.IItineraryStopsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiuli
 * @since 2024-04-16
 */
@Service
public class ItineraryStopsServiceImpl extends ServiceImpl<ItineraryStopsMapper, ItineraryStops> implements IItineraryStopsService {

    @Autowired
    private IAttractionService attractionService;

    // 根据行程ID查询行程点的数据
    @Override
    public List<ItineraryStopsVO> selectItineraryStopsByItineraryId(Long itineraryId) {
        // 1. 查询行程点的基础信息
        List<ItineraryStops> itineraryStopsList = lambdaQuery()
                .eq(ItineraryStops::getItineraryId, itineraryId)
                .list();
        if(itineraryStopsList.isEmpty()){
            return null;
        }
        // 2. 转化数据格式
        List<ItineraryStopsVO> itineraryStopsVOS = BeanUtil.copyToList(itineraryStopsList, ItineraryStopsVO.class);

        // 3. 封装其它数据
        itineraryStopsVOS
                .forEach(itineraryStopsVO -> {
                    // 1. 封装对应的景点信息咯（怎么说呢，我需要提前用到images, and title，所以就提前获取回来吧）
                    Attraction attraction = attractionService.getById(itineraryStopsVO.getAttractionId());
                    itineraryStopsVO.setAttraction(attraction);
                });

        return itineraryStopsVOS;
    }
}
